home *** CD-ROM | disk | FTP | other *** search
- /* Buttons.c */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
- #include <stdlib.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "Dispatcher.h"
- #include "DDocData.h"
- #include "EverythingEngine.h"
- #include "EverythingDoc.h"
- #include "Buttons.h"
-
-
- static EverythingEngine* GetEngine (Buttons* self);
-
- static void DoUndo (Buttons* self);
- static void DoCut (Buttons* self);
- static void DoCopy (Buttons* self);
- static void DoPaste (Buttons* self);
- static void DoClear (Buttons* self);
- static void DoSelectAll (Buttons* self);
- static void DoShowClipboard (Buttons* self);
-
-
- //----------
- Buttons* NewButtons ()
- {
- Buttons* window;
-
- window = (Buttons*)malloc (sizeof (Buttons));
- Buttons_Init (window);
- SetClassID (window, classButtons);
-
- return window;
- }
-
- //----------
- void DeleteButtons (
- Buttons* window)
- {
- Buttons_Free (window);
- free (window);
- }
-
- //----------
- void Buttons_Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- Buttons* winObj = NewButtons ();
-
- if (winObj != nil) {
- Buttons_Open (winObj, inDoc, inData);
- }
- }
-
- //----------
- void Buttons_Init (
- Buttons* self)
- {
- }
-
- //----------
- void Buttons_Free (
- Buttons* self)
- {
- }
-
- //----------
- EverythingEngine* GetEngine (
- Buttons* self)
- {
- return (EverythingEngine*) self->super.mDoc->mEngine;
- }
-
- /*----------*/
- void Buttons_Open (
- Buttons* self,
- AMDoc* inDoc,
- DDocData* inData)
- {
- WindowPtr window;
- Handle wftb;
-
- self->super.mDoc = inDoc;
- self->mData = inData;
- AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- window = GetNewCWindow (WIND_Buttons, nil, (WindowPtr) -1L);
- if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
- SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
- }
- self->super.mWindow = window;
- ((EverythingDoc*)self->super.mDoc)->mButtonsPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) self);
- SetPort (window);
- SetInfo (window);
-
- wftb = GetResource ('Wftb', WIND_Buttons);
-
- CreateRootControl (window, &self->super.mRootControl);
-
- self->super.vScroll = nil;
- self->super.hScroll = nil;
-
-
- self->mCapInvisibleLabel = GetNewControl (CNTL_CapInvisible, window);
- SetWindowItemFont (self->mCapInvisibleLabel, wftb, 1);
- SetControlFromTEXT (self->mCapInvisibleLabel, TEXT_CapInvisible);
-
- self->mInvisibleHandle = GetNewControl (CNTL_Invisible, window);
- SetWindowItemFont (self->mInvisibleHandle, wftb, 2);
-
- self->mStandardHandle = GetNewControl (CNTL_Standard, window);
- SetWindowItemFont (self->mStandardHandle, wftb, 3);
-
- self->mDefaultHandle = GetNewControl (CNTL_Default, window);
- SetWindowItemFont (self->mDefaultHandle, wftb, 4);
- SetDefaultState (self->mDefaultHandle, true);
-
- self->mBevelHandle = GetNewControl (CNTL_Bevel, window);
- SetWindowItemFont (self->mBevelHandle, wftb, 5);
-
- self->mButtonHandle = GetNewControl (CNTL_Button, window);
- EmbedControl (self->mButtonHandle, self->mBevelHandle);
- SetWindowItemFont (self->mButtonHandle, wftb, 6);
- SetBevelButtonGraphicAlignment (self->mButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
-
- self->mNextHandle = GetNewControl (CNTL_Next, window);
- EmbedControl (self->mNextHandle, self->mBevelHandle);
- SetWindowItemFont (self->mNextHandle, wftb, 7);
- SetBevelButtonTextPlacement (self->mNextHandle, kControlBevelButtonPlaceToRightOfGraphic);
- SetBevelButtonTextAlignment (self->mNextHandle, kControlBevelButtonAlignTextFlushLeft, 0);
- SetBevelButtonGraphicAlignment (self->mNextHandle, kControlBevelButtonAlignLeft, 0, 0);
-
- self->mNext2Handle = GetNewControl (CNTL_Next2, window);
- EmbedControl (self->mNext2Handle, self->mBevelHandle);
- SetWindowItemFont (self->mNext2Handle, wftb, 8);
- SetBevelButtonTextPlacement (self->mNext2Handle, kControlBevelButtonPlaceBelowGraphic);
- SetBevelButtonTextAlignment (self->mNext2Handle, kControlBevelButtonAlignTextCenter, 0);
- SetBevelButtonGraphicAlignment (self->mNext2Handle, kControlBevelButtonAlignTop, 0, 0);
-
- self->mGraphicHandle = GetNewControl (CNTL_Graphic, window);
- SetWindowItemFont (self->mGraphicHandle, wftb, 9);
-
- self->mCapcicnLabel = GetNewControl (CNTL_Capcicn, window);
- EmbedControl (self->mCapcicnLabel, self->mGraphicHandle);
- SetWindowItemFont (self->mCapcicnLabel, wftb, 10);
- SetControlFromTEXT (self->mCapcicnLabel, TEXT_Capcicn);
-
- self->mRightHandle = GetNewControl (CNTL_Right, window);
- EmbedControl (self->mRightHandle, self->mGraphicHandle);
- SetWindowItemFont (self->mRightHandle, wftb, 11);
-
- self->mCapicl8Label = GetNewControl (CNTL_Capicl8, window);
- EmbedControl (self->mCapicl8Label, self->mGraphicHandle);
- SetWindowItemFont (self->mCapicl8Label, wftb, 12);
- SetControlFromTEXT (self->mCapicl8Label, TEXT_Capicl8);
-
- self->mLightHandle = GetNewControl (CNTL_Light, window);
- EmbedControl (self->mLightHandle, self->mGraphicHandle);
- SetWindowItemFont (self->mLightHandle, wftb, 13);
-
- self->mCapICNLabel = GetNewControl (CNTL_CapICN, window);
- EmbedControl (self->mCapICNLabel, self->mGraphicHandle);
- SetWindowItemFont (self->mCapICNLabel, wftb, 14);
- SetControlFromTEXT (self->mCapICNLabel, TEXT_CapICN);
-
- self->mRight2Handle = GetNewControl (CNTL_Right2, window);
- EmbedControl (self->mRight2Handle, self->mGraphicHandle);
- SetWindowItemFont (self->mRight2Handle, wftb, 15);
-
- self->mCapicl9Label = GetNewControl (CNTL_Capicl9, window);
- EmbedControl (self->mCapicl9Label, self->mGraphicHandle);
- SetWindowItemFont (self->mCapicl9Label, wftb, 16);
- SetControlFromTEXT (self->mCapicl9Label, TEXT_Capicl9);
-
- self->mButton2Handle = GetNewControl (CNTL_Button2, window);
- EmbedControl (self->mButton2Handle, self->mGraphicHandle);
- SetWindowItemFont (self->mButton2Handle, wftb, 17);
-
- self->mRight3Handle = GetNewControl (CNTL_Right3, window);
- EmbedControl (self->mRight3Handle, self->mGraphicHandle);
- SetWindowItemFont (self->mRight3Handle, wftb, 18);
-
- self->mCapPICTLabel = GetNewControl (CNTL_CapPICT, window);
- EmbedControl (self->mCapPICTLabel, self->mGraphicHandle);
- SetWindowItemFont (self->mCapPICTLabel, wftb, 19);
- SetControlFromTEXT (self->mCapPICTLabel, TEXT_CapPICT);
-
- self->mRect3DHandle = GetNewControl (CNTL_Rect3D, window);
- SetWindowItemFont (self->mRect3DHandle, wftb, 20);
-
- self->mLeftIconHandle = GetNewControl (CNTL_LeftIcon, window);
- SetWindowItemFont (self->mLeftIconHandle, wftb, 21);
-
- self->mRightIconHandle = GetNewControl (CNTL_RightIcon, window);
- SetWindowItemFont (self->mRightIconHandle, wftb, 22);
-
- self->mTitledPICTHandle = GetNewControl (CNTL_TitledPICT, window);
- SetWindowItemFont (self->mTitledPICTHandle, wftb, 23);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- /*----------*/
- void Buttons_Close (
- Buttons* self)
- {
- RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
-
- ((EverythingDoc*)self->super.mDoc)->mButtonsPtr = nil;
- SetInfo (nil);
- HideWindow (self->super.mWindow);
- DisposeWindow (self->super.mWindow);
-
- DeleteButtons (self);
- }
-
- /*----------*/
- void Buttons_Track (
- Buttons* self,
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- if (whichControl == self->mInvisibleHandle) {
- if (TrackClick (self->mInvisibleHandle, where)) {
- }
- }
- if (whichControl == self->mStandardHandle) {
- if (TrackClick (self->mStandardHandle, where)) {
- }
- }
- if (whichControl == self->mDefaultHandle) {
- if (TrackClick (self->mDefaultHandle, where)) {
- }
- }
- if (whichControl == self->mButtonHandle) {
- if (TrackClick (self->mButtonHandle, where)) {
- }
- }
- if (whichControl == self->mNextHandle) {
- if (TrackClick (self->mNextHandle, where)) {
- }
- }
- if (whichControl == self->mNext2Handle) {
- if (TrackClick (self->mNext2Handle, where)) {
- }
- }
- if (whichControl == self->mRightHandle) {
- if (TrackClick (self->mRightHandle, where)) {
- }
- }
- if (whichControl == self->mLightHandle) {
- if (TrackClick (self->mLightHandle, where)) {
- }
- }
- if (whichControl == self->mRight2Handle) {
- if (TrackClick (self->mRight2Handle, where)) {
- }
- }
- if (whichControl == self->mButton2Handle) {
- if (TrackClick (self->mButton2Handle, where)) {
- }
- }
- if (whichControl == self->mRight3Handle) {
- if (TrackClick (self->mRight3Handle, where)) {
- }
- }
- if (whichControl == self->mRect3DHandle) {
- if (TrackClick (self->mRect3DHandle, where)) {
- }
- }
- if (whichControl == self->mLeftIconHandle) {
- if (TrackClick (self->mLeftIconHandle, where)) {
- }
- }
- if (whichControl == self->mRightIconHandle) {
- if (TrackClick (self->mRightIconHandle, where)) {
- }
- }
- if (whichControl == self->mTitledPICTHandle) {
- if (TrackClick (self->mTitledPICTHandle, where)) {
- }
- }
- }
-
- //----------
- void Buttons_DataChanged (
- Buttons* self,
- long inDataID)
- {
- }
-
- /*----------*/
- void Buttons_MouseIn (
- Buttons* self,
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void Buttons_ExitCurField (
- Buttons* self)
- {
- ControlHandle focus;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- /*----------*/
- void Buttons_TypeIn (
- Buttons* self,
- char ch)
- {
- ControlHandle focus;
- short keyCode;
-
- GetKeyboardFocus (self->super.mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- Buttons_ExitCurField (self); // Dispatch
- SimulateClick (self->mDefaultHandle);
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = curEvent.message & keyCodeMask;
- HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- } else {
- SysBeep (1);
- }
- }
-
- /*----------*/
- void Buttons_Resize (
- Buttons* self)
- {
- /* application-specific code to resize items in window */
- }
-
- /*----------*/
- void Buttons_Scroll (
- Buttons* self,
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == self->super.vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void DoUndo (
- Buttons* self)
- {
- } // DoUndo
-
- //----------
- void DoCut (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECut (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void DoCopy (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void DoPaste (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEPaste (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoPaste
-
- //----------
- void DoClear (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TEDelete (curTE);
- AMEngine_SetDirty (self->super.mDoc->mEngine);
- }
- } // DoClear
-
- //----------
- void DoSelectAll (
- Buttons* self)
- {
- TEHandle curTE = AMWindow_GetCurTE ((AMWindow*) self);
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void DoShowClipboard (
- Buttons* self)
- {
- } // DoShowClipboard
-
- //----------
- Boolean Buttons_DoCommand (
- Buttons* self,
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo (self);
- break;
- case cmdCut:
- DoCut (self);
- break;
- case cmdCopy:
- DoCopy (self);
- break;
- case cmdPaste:
- DoPaste (self);
- break;
- case cmdClear:
- DoClear (self);
- break;
- case cmdSelectAll:
- DoSelectAll (self);
- break;
- case cmdShowClipboard:
- DoShowClipboard (self);
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-